<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="left-panel"> </div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 摘要" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="meetingId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="会议类型" prop="meetingTypeName" width="100"></el-table-column>
				<el-table-column label="会议主题" prop="subject" width="250" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="会议室" prop="roomName" width="150"></el-table-column>
				<el-table-column label="预约状态" prop="sex" width="100">
					<template #default="scope">
						<el-tag v-if="scope.row.status=='0'">预约中</el-tag>
						<el-tag v-if="scope.row.status=='1'" type="success">预约成功</el-tag>
						<el-tag v-if="scope.row.status=='2'" type="warning">预约失败</el-tag>
						<el-tag v-if="scope.row.status=='3'" type="info">取消</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="会议主持" prop="chairUserName" width="150"></el-table-column>
				<el-table-column label="开始时间" prop="beginTime" width="150"></el-table-column>
				<el-table-column label="结束时间" prop="endTime" width="150"></el-table-column>
				<el-table-column label="联系电话" prop="tel" width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-popconfirm title="确定提醒吗？" @confirm="sendMeetingMsg(scope.row, scope.$index)" v-if="scope.row.status=='1'">
								<template #reference>
									<el-button text type="primary" size="small">提醒</el-button>
								</template>
							</el-popconfirm>
							<el-popconfirm title="确定取消吗？" @confirm="cancelMeeting(scope.row, scope.$index)" v-if="scope.row.status=='1'">
								<template #reference>
									<el-button text type="primary" size="small">取消</el-button>
								</template>
							</el-popconfirm>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)" v-if="scope.row.status=='0'">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<meeting-details v-if="dialog.save" ref="detailsDialog" @closed="dialog.save=false"></meeting-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import MeetingDetails from "@/views/office/meeting/meetingDetails";
export default {
	name: 'Mu Apply Meeting',
	components: {
		scSelectFilter,
		MeetingDetails
	},
	data() {
		return {
			dialog: {
				save: false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "会议类型",
					key: "meetingType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "会议室",
					key: "roomId",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}],
				}
			],

			apiObj: this.$API.office.meeting.getMyApplyMeetingList,
			search: {
				date:'',
				meetingType:'',
				roomId:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode();
	},
	methods: {
		async getSysDicByCode()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'meetingType'});
			if (res.code == 200) {
				if(res.data){
					this.filterData[1].options=this.filterData[1].options.concat(res.data);
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
			res = await this.$API.office.meeting.getMyApplyMeetingRoomList.get();
			if (res.code == 200) {
				if(res.data) {
					this.filterData[2].options = this.filterData[2].options.concat(res.data);
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.meetingType = data.meetingType;
			this.search.roomId = data.roomId;
			this.$refs.table.upData(this.search)
		},
		//编辑
		async cancelMeeting(row) {
			var reqData = {meetingId: row.meetingId}
			var res = await this.$API.office.meeting.cancelMeeting.post(reqData);
			if (res.code == 200) {
				this.$message.success("会议取消提醒发送成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async sendMeetingMsg(row) {
			var reqData = {meetingId: row.meetingId}
			var res = await this.$API.office.meeting.sendMeetingMsg.post(reqData);
			if (res.code == 200) {
				this.$message.success("会议提醒发送成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row);
			})
		},
		//删除
		async table_del(row) {
			var reqData = {meetingId: row.meetingId}
			var res = await this.$API.office.meeting.deleteMeeting.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
</style>
